var romanToInt = function (s) {
    const map = {
        I: 1,
        V: 5,
        X: 10,
        L: 50,
        C: 100,
        D: 500,
        M: 1000
    }
    let sum = 0;
    for (let i = 0; i < s.length; i++) {
        let key = s[i];
        let val = map[s[i]]
        // console.log(map[s[i]]);
        if (map[key] < map[s[i + 1]]) {
            val = map[s[i + 1]] - map[key]
            i++
        }
        sum += val
    }
    return sum
}


console.log(romanToInt("LVIII"))
